package com.atguigu.jxc.controller;

import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.entity.CustomerReturnList;
import com.atguigu.jxc.entity.CustomerReturnListGoods;
import com.atguigu.jxc.service.CustomerReturnListGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("customerReturnListGoods")
public class CustomerReturnListGoodsController {

    @Autowired
    private CustomerReturnListGoodsService customerReturnListGoodsService;
    /*
    http://localhost:8080/customerReturnListGoods/save?returnNumber=XT1605772786495（退货单号）
    请求参数：CustomerReturnList customerReturnList, String customerReturnListGoodsStr
    请求方式：POST
    返回值类型：JSON
    返回值：ServiceVO
     */
    //客户退货单保存
    @PostMapping("save")
    public ServiceVO save(CustomerReturnList customerReturnList,
                          String customerReturnListGoodsStr,
                          String returnNumber){
        return customerReturnListGoodsService.save(customerReturnList,customerReturnListGoodsStr,returnNumber);
    }
    /*
    请求URL：http://localhost:8080/customerReturnListGoods/list
    请求参数：String returnNumber, Integer customerId, Integer state, String sTime,String eTime
    请求方式：POST
    返回值类型：JSON
    返回值：Map<String,Object>
     */
    //客户退货单查询（可查询条件：退货单号、客户、退款状态）
    @PostMapping("list")
    public Map<String,Object> list(String returnNumber, Integer customerId, Integer state, String sTime,String eTime){
        List<CustomerReturnList> list=customerReturnListGoodsService.getList(returnNumber,customerId,state,sTime,eTime);
        Map<String, Object> map = new HashMap<>();
        map.put("rows",list);
        return map;
    }

    /*
    请求URL：http://localhost:8080/customerReturnListGoods/goodsList
    请求参数：Integer customerReturnListId
    请求方式：POST
    返回值类型：JSON
    返回值：Map<String,Object>
     */
    //退货单商品信息详情
    @PostMapping("goodsList")
    public Map<String,Object> goodsList(Integer customerReturnListId){
        List<CustomerReturnListGoods> list=customerReturnListGoodsService.goodsList(customerReturnListId);
        Map<String, Object> map = new HashMap<>();
        map.put("rows",list);
        return map;
    }

    /*
    请求URL：http://localhost:8080/customerReturnListGoods/delete
    请求参数：Integer customerReturnListId
    请求方式：POST
    返回值类型：JSON
    返回值：ServiceVO
     */
    //删除退货单
    @PostMapping("delete")
    public ServiceVO delete(Integer customerReturnListId){
        return customerReturnListGoodsService.delete(customerReturnListId);
    }
}
